<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="textml; charset=utf-8" />
<title></title>
<style>
div{
	width:100px;
	height:100px;
	background:red;
}
</style>
<script type="text/javascript">
function getStyle(obj,name)
{
	    if(obj.currentStyle)
		{
			return obj.currentStyle[name];
		}
	    else
		{
			return getComputedStyle(obj,false)[name];
		}
};
   window.onload=function()
	{
		var odiv1=document.getElementById('div1');
		var odiv2=document.getElementById('div2');
			odiv1.onmouseover=function(){
				
                  change(this,'width',400);
                  
			};
			odiv1.onmouseout=function(){
                  change(this,'width',100);
			};
			
			odiv2.onmouseover=function(){
				
                  change(this,'height',400);
                  
			};
			odiv2.onmouseout=function(){
                  change(this,'height',100);
			};
	};
	function change(obj,attr,tag){
        clearInterval(obj.timer);
       obj.timer=setInterval(function(){
        	var cur=parseInt(getStyle(obj,[attr]));
        	
        	var speed=(tag-cur)/6;
        	speed=speed>0?Math.ceil(speed):Math.floor(speed);
        	if(tag==cur)
        	{
        		clearInterval(obj.timer);
        	}
        	else
        	{
        		obj.style[attr]=cur+speed+'px';
        	}
        },30);
	};
</script>
</head>
<body>
<div id="div1">
变宽
</div>
<div id="div2">
变高 
</div>
</body>
</html>
